home *** CD-ROM | disk | FTP | other *** search
- Subject: Subtle "bug" in ODFContaine
- Sent: 5/23/96 11:16 AM
- Received: 5/23/96 11:31 AM
- From: Kirk Swenson, kswenson@mail.keypress.com
- Reply-To: ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- First, let me join in the chorus of favorable responses to ODF R1. The
- improvements from d11 are even greater than I had expected. In moving our
- part to ODF R1, however, I have stumbled across one minor problem that people
- might want to be aware of.
-
- In ODF R1, ODFContainer's Content.cpp won't compile in CW8 if any of the CW8
- STL header files are included. This makes it difficult to use STL containers
- as part of the content model for an embedding part, since PartMaker uses
- ODFContainer as the template for embedding parts.
-
- The problem is in the following lines in CBaseContent::RedrawProxies():
-
- FW_CAcquiredODShape updateShape = CalcUpdateShape(ev);
- if (updateShape != NULL)
-
- The template class that defines FW_CAcquiredODShape,
- FW_TAcquiredODRefCntObject, declares two operator!=() functions, neither of
- which handles a void* operand automatically. When an STL header file is
- included, the compiler tries to bind the comparison to STL's global
- operator!=() defined in STL's <function.h>, which generates a compiler error
- about incompatible operands. (The line number given by the compiler for the
- error is in <function.h>, which makes it a bit tricky to figure out where in
- Content.cpp the problem is.)
-
- The local fix is to replace the comparison with
-
- if (updateShape != (ODShape*) NULL)
-
- or, for those who prefer the newer cast style
-
- if (updateShape != static_cast<ODShape*>(NULL))
-
- This matches one of the operator!=() defined by
- FW_TAcquiredODRefCntObject<ODShape>, which forces the compiler to select the
- correct operator!=(), and everything compiles.
-
- Alternatively, FW_TAcquiredODRefCntObject could be modified, perhaps by
- adding an operator!() which would compare against NULL automatically, and
- allow the above code to be rewritten
-
- if (!updateShape)
-
- which prevents the client from having to know what the internal pointer
- really is.
-
- The original code compiles correctly when STL header files are not involved
- because the compiler will coerce NULL to be an ODShape* if it doesn't see any
- better alternatives. When it sees STL's global operator!=(), however, it
- tries to bind that way instead. I haven't worked through the C++ operand
- resolution order to determine exactly why the global operator is preferred in
- this case, but that's what the compiler seems to be doing.
-
- This detail aside, however, we are very pleased with ODF R1.
- Keep up the good work!
-
- Kirk Swenson
- Senior Software Engineer
- Key Curriculum Press
- Emeryville, CA
- kswenson@keypress.com
-
-